<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserMemberCardsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_member_cards', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('=users.id');
            $table->integer('shop_id')->default(0)->comment('=shops.id');
            $table->integer('card_id')->default(0)->comment('=present_cards.id');
            $table->tinyInteger('card_type')->default(0)->comment('1赠送卡2礼品卡');
            $table->tinyInteger('card_level')->default(1)->comment('1月卡2季卡3年卡');
            $table->string('code')->unique()->comment('会员卡卡号');
            $table->tinyInteger('is_used')->default('0')->comment('是否被使用');
            $table->integer('used_by')->default('0')->comment('=users.id被谁使用');
            $table->dateTime('used_at')->nullable()->comment('使用时间');
            $table->timestamps();
        });
        DB::statement("ALTER TABLE `user_member_cards` comment '用户会员卡';");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_member_cards');
    }
}
